package com.shundr.order.http;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.shundr.common.util.JsonUtil;
import com.shundr.order.model.CargoOrderInfo;

/**
 * 订单解析公共类
 * OrderParser
 * 
 * @author larry 2015-4-13 下午5:37:27 
 * @version 1.0.0
 *
 */
public class OrderParser {

	/**
	 * 
	 * parserOrderList(这里用一句话描述这个方法的作用) 解析订单列表
	 * (这里描述这个方法适用条件 – 可选)
	 * @param data
	 * @return
	 * List<CargoOrderInfo>
	 * @exception
	 * @since  1.0.0
	 */
	public static List<CargoOrderInfo> parserOrderList(String data) {
		try {
			JSONObject obj = new JSONObject(data);
			JSONArray array = obj.getJSONArray("cargoOrderInfoList");
			List<CargoOrderInfo> infos = JsonUtil.getList(array.toString(), CargoOrderInfo.class);
			return infos;
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return new ArrayList<CargoOrderInfo>();
	}
	
	public static CargoOrderInfo parserOrderInfo(String data) {
		try {
			CargoOrderInfo infos = JsonUtil.fromJson(data, CargoOrderInfo.class);
			return infos;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new CargoOrderInfo();
	}

}
